<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

if(!$_SESSION) session_start();
// Connect to the database
////////////////////////////////////////////////////////

require_once("scripts/config.php");

// Load Functions
////////////////////////////////////////////////////////

require_once("scripts/functions.php");


// Sign Out User
///////////////////////////////////////////////////////

if($_GET['action']=="signout"){

    foreach($_SESSION as $key => $value){

        unset($_SESSION[$key]);

    }

    header("Location:index.php");
}

// Process Login
///////////////////////////////////////////////////////

if(isset($_POST['formVSI']) && $_POST['formVSI']=="process"){

    $sql = sprintf("SELECT * FROM tblusers WHERE email_address = %s AND password = %s AND set_active = 1",

        GetSQLValueString($_POST['userEmail'], "text"),
        GetSQLValueString($_POST['userPass'], "text"));

    $user = sqlLoad($sql, $db);
	
	if(!isset($_POST['set_agreement']) && $_POST['set_agreement'] != 1){
		
		unset($user);
		
	}
	
    $error = "Sign Unsuccessful, please try again!";

    if(sizeof($user)==1){

        // Create user object
        //////////////////////////////////

        foreach ($user as $usr){

            foreach ($usr as $uk => $uv){

                $_SESSION[$uk] = $uv;

            }

        }

        header("Location:home.php");

    }

}

?>
<html>
    <head>
        <title>Sign In | SynergyBugs - SynergyMX.com</title>
    <link href="/scripts/style.css" rel="stylesheet" type="text/css">
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
    <style>
	#userEmail { width:300px; border:1px solid #666;}
	#userPass { width:300px; border:1px solid #666;}
	</style>
<body>

        <form name="formVSI" id="formVSI" action="index.php" method="post">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td class="tnbg" align="center"><div style="width:780px; text-align: left"><img src="/images/logo.png" width="195" height="56"></div></td>
              </tr>
              <tr>
                <td><table align="center">
                  <tr>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td>Please Sign In</td>
                  </tr>
                  <?php if(strlen($error)>0){ ?>
                  <tr>
                    <td><?php echo $error;?></td>
                  </tr>
                  <?php } ?>
                  <tr>
                    <td><input name="userEmail" type="text" class="ft20" id="userEmail">
                      user</td>
                  </tr>
                  <tr>
                    <td><input type="password" name="userPass" id="userPass">
                      password</td>
                  </tr>
                  <tr>
                    <td><label class="ft8">
                      <input type="checkbox" name="set_agreement" id="set_agreement" value="1">
                      I agree to the <a href="http://www.synergymx.com/">SynergyMX Terms of Service</a> and the <a href="http://www.mozilla.org/MPL/MPL-1.1.html" target="_blank">Mozilla Public License 1.1</a></label></td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td><input type="submit" id="submit" value="Sign In">
                      <input type="hidden" id="formVSI" name="formVSI" value="process"></td>
                  </tr>
                </table></td>
              </tr>
              <tr>
                <td height="25" align="center" valign="bottom" class="ft8"><a href="https://code.google.com/p/synergybugs/">SynergyBugs</a> &copy; SynergyMX, Inc. version 2010.11.13.03.00.05 Licensed under <a href="http://www.mozilla.org/MPL/MPL-1.1.html">Mozilla Public License 1.1</a></td>
              </tr>
            </table>
            <p>Having unresolved issues with SyneryBugs? <a href="https://code.google.com/p/synergybugs/issues/list" target="_blank">Post it here!</a></p>
</form>

    </body>
</html>